Purpose
The search task takes a regular expression (RegExp) and a string and searches for that RegExp within the string. A RegExp can contain both special and ordinary characters. The task returns an index (number) to indicate the position where a match is found. Indexing starts from zero (0). The task returns -1 if no match is found.
Potential Use Case
The search task checks if a particular string matches for a given RegExp, or search pattern. You could use this method to simply check if a certain pattern exists and also know its index within a string. In conjunction with the substr method, you could use search to find and replace text in a data record.
Properties
Input and output properties are shown below.
| Input | Type | Description | 
|---|---|---|
| str | String | Required. The string (or substring) to search. | 
| regexp | String | Required. The search pattern to match in the regular expression. | 
| Output | Type | Description | 
|---|---|---|
| index | Number | The position where the first match between the regular expression and the given string is found. Returns -1 if not found. Of note, the outgoing index of the first character begins with 0, the second character 1, and so on. | 
Examples
Example 1
In the IAP examples shown below:
- The incoming - strvariable is statically set. The reference variable is- Hello World.
- The search pattern to match in the - regexpvariable is- or. 
- The - indexresult will return- 7upon output, indicating the- regexp("or") is located at index position 7 in the string. 
Example 2
In the IAP examples shown below:
- The reference variable for the incoming - stris- Hey Dr. Livingstone.
- The search pattern to match in the - regexpvariable is- \., which is a special notation (character class) to indicate the match should be a period (".").- Refer to this resource for more information on using character classes in regular expressions.  
- The - indexresult returns- 6upon output, indicating the period is located at index position 6 in the string. 
Example 3
In the IAP examples shown below:
- The incoming - strvariable is statically set. The reference variable is- Hey Judey.
- The - regexpvariable is statically set as- \., a character class notation to indicate the match should be a period ("."). 
- The - indexresult returns- -1upon output, indicating a period was not found in the string.